var ocx = null;
var preWindowIndex=0;
var indexcodes = [];
var ISPREVIEW=1; /* 正在预览*/
var NOTPREVIEW=0; /* 没在预览*/
//token设置事件通知
function tokenCallEvent(reqID) {
	$.ajax({
		url : "getVmsToken",
		type : "post",
		dataType : "text",
		success : function(token) {
			ocx.setToken(reqID, token);
		}
	});
}

function preview(indexCode) {
	if(ocx == null){
		var preview = { divId : "camera1"};
		ocx = new PreviewOCX(preview);
		//设置token回调
		ocx.registerCallback(PREVIEW_EVENT_TOKEN, tokenCallEvent);
	}
	$.ajax({
		url : "getHikvisionStream",
		type : "post",
		dataType : "text",
		data : {indexCode : indexCode},
		success : function(xml) {
			ocx.setWindowsLayout(layout_1X1 = 1);
			var winindex = ocx.getSelectWindow();
			ocx.startPreview(winindex, xml)		
//			if(ocx.setSelectWindow(winindex+1)==-1){
//				ocx.setSelectWindow(0);
//			}
//			}
			},
		error : function(data){
			ocx.setWindowsLayout(layout_1X1 = 1);
		}
	});
}
		
function stopPreview(){
	ocx.stopPreview(-1);
}